﻿using System;
using System.Collections.Generic;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.pp.processor.type.comm;
using SharpSqlAnalyzer.pp.processor.type.select;
using SharpSqlAnalyzer.stmt;

namespace SharpSqlAnalyzer.pp.stmtformatter.type.comm
{
	// Token: 0x02000211 RID: 529
	public class SelectStmtFormatter : AbstractStmtFormatter
	{
		// Token: 0x06001233 RID: 4659 RVA: 0x00318335 File Offset: 0x00316535
		public virtual void addItemListProcessor(AbstractProcessor p)
		{
			if (this.itemListProcessors == null)
			{
				this.itemListProcessors = new List<AbstractProcessor>();
			}
			this.itemListProcessors.Add(p);
		}

		// Token: 0x06001234 RID: 4660 RVA: 0x00318356 File Offset: 0x00316556
		public virtual void addItemListAlignProcessor(AbstractProcessor p)
		{
			if (this.itemListAlignProcessors == null)
			{
				this.itemListAlignProcessors = new List<AbstractProcessor>();
			}
			this.itemListAlignProcessors.Add(p);
		}

		// Token: 0x06001235 RID: 4661 RVA: 0x00318377 File Offset: 0x00316577
		public virtual void addTableClauseProcessor(AbstractProcessor p)
		{
			if (this.tableClauseProcessors == null)
			{
				this.tableClauseProcessors = new List<AbstractProcessor>();
			}
			this.tableClauseProcessors.Add(p);
		}

		// Token: 0x06001236 RID: 4662 RVA: 0x00318398 File Offset: 0x00316598
		public virtual void addFromJoinClauseProcessor(AbstractProcessor p)
		{
			if (this.fromJoinClauseProcessors == null)
			{
				this.fromJoinClauseProcessors = new List<AbstractProcessor>();
			}
			this.fromJoinClauseProcessors.Add(p);
		}

		// Token: 0x06001237 RID: 4663 RVA: 0x003183B9 File Offset: 0x003165B9
		public virtual void addGroupByClauseProcessor(AbstractProcessor p)
		{
			if (this.groupByClauseProcessors == null)
			{
				this.groupByClauseProcessors = new List<AbstractProcessor>();
			}
			this.groupByClauseProcessors.Add(p);
		}

		// Token: 0x06001238 RID: 4664 RVA: 0x003183DA File Offset: 0x003165DA
		public virtual void addOrderByClauseProcessor(AbstractProcessor p)
		{
			if (this.orderByClauseProcessors == null)
			{
				this.orderByClauseProcessors = new List<AbstractProcessor>();
			}
			this.orderByClauseProcessors.Add(p);
		}

		// Token: 0x06001239 RID: 4665 RVA: 0x003183FB File Offset: 0x003165FB
		public virtual void addWhereClauseProcessor(AbstractProcessor p)
		{
			if (this.whereClauseProcessors == null)
			{
				this.whereClauseProcessors = new List<AbstractProcessor>();
			}
			this.whereClauseProcessors.Add(p);
		}

		// Token: 0x0600123A RID: 4666 RVA: 0x0031841C File Offset: 0x0031661C
		public virtual void addWhereExpProcessors(AbstractProcessor p)
		{
			if (this.whereExpProcessors == null)
			{
				this.whereExpProcessors = new List<AbstractProcessor>();
			}
			this.whereExpProcessors.Add(p);
		}

		// Token: 0x0600123B RID: 4667 RVA: 0x0031843D File Offset: 0x0031663D
		public virtual void addHavingClauseProcessor(AbstractProcessor p)
		{
			if (this.havingClauseProcessors == null)
			{
				this.havingClauseProcessors = new List<AbstractProcessor>();
			}
			this.havingClauseProcessors.Add(p);
		}

		// Token: 0x0600123C RID: 4668 RVA: 0x0031845E File Offset: 0x0031665E
		public virtual void addIntoClauseProcessor(AbstractProcessor p)
		{
			if (this.intoClauseProcessors == null)
			{
				this.intoClauseProcessors = new List<AbstractProcessor>();
			}
			this.intoClauseProcessors.Add(p);
		}

		// Token: 0x0600123D RID: 4669 RVA: 0x00318480 File Offset: 0x00316680
		protected internal override void doFormat(TCustomSqlStatement sqlArg)
		{
			TSelectSqlStatement tselectSqlStatement = sqlArg as TSelectSqlStatement;
			bool flag = false;
			if (tselectSqlStatement.LeftStmt != null || tselectSqlStatement.RightStmt != null)
			{
				flag = true;
			}
			if (flag)
			{
				TSelectSqlStatement leftStmt = tselectSqlStatement.LeftStmt;
				if (leftStmt != null)
				{
					this.format(leftStmt);
				}
				if (this.unionProcessor != null)
				{
					this.runProcessor<TSelectSqlStatement>(new List<AbstractProcessor>
					{
						this.unionProcessor
					}, tselectSqlStatement);
				}
				TSelectSqlStatement rightStmt = tselectSqlStatement.RightStmt;
				if (rightStmt != null)
				{
					this.format(rightStmt);
				}
				return;
			}
			this.formatSingleStatmenet(tselectSqlStatement);
		}

		// Token: 0x0600123E RID: 4670 RVA: 0x003184FC File Offset: 0x003166FC
		private void formatSingleStatmenet(TSelectSqlStatement sql)
		{
			this.runProcessor<TSelectSqlStatement>(this.SpecialProcessors, sql);
			TResultColumnList resultColumnList = sql.ResultColumnList;
			this.runProcessor<TResultColumnList>(this.itemListProcessors, resultColumnList);
			if (resultColumnList != null)
			{
				for (int i = 0; i < resultColumnList.size(); i++)
				{
					TResultColumn resultColumn = resultColumnList.getResultColumn(i);
					if (resultColumn.Expr != null)
					{
						this.runProcessor<TExpression>(this.ExpressionProcessors, resultColumn.Expr);
					}
				}
			}
			this.runProcessor<TResultColumnList>(this.itemListAlignProcessors, resultColumnList);
			TTableList tables = sql.tables;
			this.runProcessor<TTableList>(this.tableClauseProcessors, tables);
			this.runProcessor<TSelectSqlStatement>(this.fromJoinClauseProcessors, sql);
			if (sql.WhereClause != null)
			{
				this.runProcessor<TExpression>(this.whereClauseProcessors, sql.WhereClause.Condition);
				this.runProcessor<TExpression>(this.whereExpProcessors, sql.WhereClause.Condition);
			}
			if (sql.GroupByClause != null)
			{
				TGroupByItemList items = sql.GroupByClause.Items;
				if (items.size() > 0)
				{
					this.runProcessor<TGroupByItemList>(this.groupByClauseProcessors, items);
				}
				TExpression havingClause = sql.GroupByClause.HavingClause;
				if (havingClause != null)
				{
					this.runProcessor<TExpression>(this.havingClauseProcessors, havingClause);
					this.runProcessor<TExpression>(this.ExpressionProcessors, havingClause);
				}
			}
			if (sql.OrderbyClause != null)
			{
				TOrderByItemList items2 = sql.OrderbyClause.Items;
				if (items2.size() > 0)
				{
					this.runProcessor<TOrderByItemList>(this.orderByClauseProcessors, items2);
					for (int j = 0; j < items2.size(); j++)
					{
						this.runProcessor<TExpression>(this.ExpressionProcessors, items2.getOrderByItem(j).SortKey);
					}
				}
			}
			TJoinList joins = sql.joins;
			for (int k = 0; k < joins.size(); k++)
			{
				TJoin join = joins.getJoin(k);
				for (int l = 0; l < join.JoinItems.Count; l++)
				{
					TJoinItem tjoinItem = join.JoinItems[l];
					if (tjoinItem != null && tjoinItem.OnCondition != null)
					{
						this.runProcessor<TExpression>(this.ExpressionProcessors, tjoinItem.OnCondition);
					}
				}
			}
			if (sql.IntoClause != null)
			{
				this.runProcessor<TExpressionList>(this.intoClauseProcessors, sql.IntoClause.ExprList);
			}
		}

		// Token: 0x1700034A RID: 842
		// (get) Token: 0x0600123F RID: 4671 RVA: 0x0031870E File Offset: 0x0031690E
		// (set) Token: 0x06001240 RID: 4672 RVA: 0x00318716 File Offset: 0x00316916
		public virtual UnionProcessor UnionProcessor
		{
			get
			{
				return this.unionProcessor;
			}
			set
			{
				this.unionProcessor = value;
			}
		}

		// Token: 0x040013E6 RID: 5094
		private IList<AbstractProcessor> itemListProcessors;

		// Token: 0x040013E7 RID: 5095
		private IList<AbstractProcessor> itemListAlignProcessors;

		// Token: 0x040013E8 RID: 5096
		private IList<AbstractProcessor> tableClauseProcessors;

		// Token: 0x040013E9 RID: 5097
		private IList<AbstractProcessor> fromJoinClauseProcessors;

		// Token: 0x040013EA RID: 5098
		private IList<AbstractProcessor> groupByClauseProcessors;

		// Token: 0x040013EB RID: 5099
		private IList<AbstractProcessor> orderByClauseProcessors;

		// Token: 0x040013EC RID: 5100
		private IList<AbstractProcessor> whereClauseProcessors;

		// Token: 0x040013ED RID: 5101
		private IList<AbstractProcessor> whereExpProcessors;

		// Token: 0x040013EE RID: 5102
		private IList<AbstractProcessor> havingClauseProcessors;

		// Token: 0x040013EF RID: 5103
		private IList<AbstractProcessor> intoClauseProcessors;

		// Token: 0x040013F0 RID: 5104
		private UnionProcessor unionProcessor;
	}
}
